$(function(){
	loadDatas();
	
	//初始化日期控件
  	$('#bt').datetimepicker({
  		language: 'zh-CN',
	    format: 'yyyy-mm-dd hh:00',
	    autoclose: true,
	    minuteStep: 1,
	    minView: "day"
	});
	
	//加载游戏平台下拉数据
	loadGamePlatformForDataCount();
	
});

function findAll(){
//	$("#begin_time, #end_time").val("");
	$("#reset").click();
	loadDatas();
}
//查询数据
function loadDatas(){
	//初始化话费总览统计图的div
	$("#onlineDataCount").html("").css({color: "",height: "300px", lineHeight: ""});
	
	//加载话费总览统计图
	loadCountCharts();
	
	//今日总产出、总产出数据、话费总览表格数据
	loadHuaFeiAllOutput();
	
}

//加载话费产出统计图
function loadCountCharts(){
	//游戏平台
	var gamePlatform = $("#gamePlatform").val();
	//用户类型
	var userType = $("#userType").val();
	//开始时间
	var begin = $("#begin_time").val();
	$.ajax({
		type:"post",
		data: {"gamePlatform": gamePlatform, "userType": userType, "begin": begin},
		url:"../../../php/charts/userOnlineCount/loadOnlineCountChart.php",
		beforeSend: function(){
			$("#load").css("display","block");
		},
		success: function(msg){
			$("#load").css("display","none");
			var datas = msg.counts;
			
			if(datas.length == 0){
				$("#onlineDataCount").html("没查询到符合条件的数据~").css({color: "red",height: "100px", lineHeight: "100px"});
			}else{
				//加载曲线图
				Morris.Area({
				    element: 'onlineDataCount',
				    behaveLikeLine: false,
				    gridTextFamily: '微软雅黑',
				    data: datas,
				    xkey: 'x',
				    ykeys: 'y',
				    labels: ['在线'],
				    lineColors:['#6dc5a3'],
				    smooth: true, //幅度效果
				    hideHover: true, //滑鼠移出图表时，提示框是否隐藏
				    parseTime: false,
				    units: '人',//单位
				    pointSize: 0,//点的直径
//				    lineWidth: 1 //线的宽度
				});
			}
		}
	});
}

//加载各房间当前在线人数表格数据
function loadHuaFeiAllOutput(){
	$.ajax({
		type:"post",
		url:"../../../php/charts/userOnlineCount/loadOnlineCountData.php",
		beforeSend: function(){
			$("#load").css("display","block");
		},
		success: function(msg){
			$("#load").css("display","none");
			//游戏平台当前在线
			$("#nowOnline").html(msg.nowOnline);
			
			//加载话费总览表格
			loadDataTable(msg.records);
		}
	});
}

//加载当前在线人数数据表格
function loadDataTable(datas){
	$("#tishiTr").remove();
	$('#dataTable').bootstrapTable({
	    columns: [{
	        field: 'kindId',
	        title: 'KindID'
	    }, {
	        field: 'roomName',
	        title: '房间'
	    }, {
	        field: 'count',
	        title: '当前在线人数'
	    }],
	    data: datas,
	    striped: true, //是否显示斑马线
	    detailView: true,//显示详细页面模式
	    detailFormatter: function(index, row){
	    	var kindId = row.kindId;
			getDetail(kindId);
			
			return "<div id='detail_"+kindId+"'></div>";
	    }
	});
}

//得到房间在线人数详情
function getDetail(kindId){
	$.ajax({
		type:"post",
		data: {"kindId": kindId},
		url:"../../../php/charts/userOnlineCount/loadOnlineCountDetail.php",
		async:true,
		beforeSend: function(){
			$("#load").css("display","block");
		},
		success: function(msg){
			$("#load").css("display","none");
			var rows = msg.records;
			
			var html = "<table class='table table-bordered table-condensed table-hover'>";
			if(rows.length == 0){
				html += "<tr><td colspan='2'>暂无数据~</td></tr>";
			}else{
				for(var i = 0; i < rows.length; i ++){
					html += "<tr><td width='50%'>"+rows[i].roomName+"</td><td>"+rows[i].count+"人</td></tr>";
				}
			}
			html += "</table>";
			$("#detail_"+kindId).html(html);
		}
	});
}